package cate.game.attr;

import cate.common.table.item.fairy.row.FairyBaseRow;
import cate.common.table.item.hero.row.HeroBaseRow;
import cate.game.play.support.PlayBuildContext;
import cate.game.role.bag.fairy.FairiesOn;
import cate.game.role.bag.fairy.Fairy;
import cate.game.role.bag.hero.Hero;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class FairysPowerAttrPart extends PowerAttrPart {

    public FairysPowerAttrPart(){}

    public FairysPowerAttrPart(PlayBuildContext ctx, FairiesOn po) {
        if (po == null) {
            return;
        }
        Hero hero = po.owner;
        if (hero == null) {
            return;
        }
        HeroBaseRow heroBaseRow = hero.getTpl(ctx);
        if (heroBaseRow == null) {
            return;
        }
        int camp = heroBaseRow.camp;
        FightAttr attr = new FightAttr();
        if (po.fairyMap != null) {
            for (Fairy fairy : po.fairyMap.values()) {
                FairyBaseRow row = fairy.getTpl(ctx);
                if (row == null) {
                    continue;
                }
                // 仙器基础属性
                FightAttr baseAttr = new FightAttr(row.attrStr);
                if (row.type == 0 && row.camp != 0 && camp != row.camp) {
                    baseAttr.scale(0.5);
                }
                attr.add(baseAttr);
            }
        }
        this.attr = attr;
        this.powerExt = 0;
        this.skills = po.getSkills(ctx);
    }
}
